package com.ruoyi.hualian.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.hualian.mapper.HlOtherCommodityDetailsMapper;
import com.ruoyi.hualian.domain.HlOtherCommodityDetails;
import com.ruoyi.hualian.service.IHlOtherCommodityDetailsService;

/**
 * 其他型号详情Service业务层处理
 * 
 * @author hujian
 * @date 2024-02-28
 */
@Service
public class HlOtherCommodityDetailsServiceImpl implements IHlOtherCommodityDetailsService 
{
    @Autowired
    private HlOtherCommodityDetailsMapper hlOtherCommodityDetailsMapper;

    /**
     * 根据集合插入数据库
     * @param hlOtherCommodityDetailsList 集合
     * @return 结果
     */
    @Override
    public int insertList(List<HlOtherCommodityDetails> hlOtherCommodityDetailsList) {
        return hlOtherCommodityDetailsMapper.insertList(hlOtherCommodityDetailsList);
    }

    /**
     * 根据已知信息查询具体对象信息
     * @param otherCommodityDetails 已知信息
     * @param type 类型
     * @return 具体对象信息
     */
    @Override
    public HlOtherCommodityDetails selectOne(HlOtherCommodityDetails otherCommodityDetails, String type) {
        LambdaQueryWrapper<HlOtherCommodityDetails> hlOtherCommodityDetailsWrapper = new LambdaQueryWrapper<>();

        hlOtherCommodityDetailsWrapper.eq(HlOtherCommodityDetails::getCode, otherCommodityDetails.getCode())
                .eq(HlOtherCommodityDetails::getTeeth, otherCommodityDetails.getTeeth());

        if (ObjectUtils.isNotEmpty(otherCommodityDetails.getBandwidth())) {
            hlOtherCommodityDetailsWrapper.eq(HlOtherCommodityDetails::getBandwidth, otherCommodityDetails.getBandwidth());
        }
        if (ObjectUtils.isNotEmpty(otherCommodityDetails.getShaftDiameter())) {
            hlOtherCommodityDetailsWrapper.eq(HlOtherCommodityDetails::getShaftDiameter, otherCommodityDetails.getShaftDiameter());
        }
        hlOtherCommodityDetailsWrapper.last("limit 1");
        HlOtherCommodityDetails hlOtherCommodityDetails = hlOtherCommodityDetailsMapper.selectOne(hlOtherCommodityDetailsWrapper);

        if (ObjectUtils.isEmpty(hlOtherCommodityDetails)) {
            hlOtherCommodityDetailsWrapper = new LambdaQueryWrapper<>();
            hlOtherCommodityDetailsWrapper.eq(HlOtherCommodityDetails::getCode, otherCommodityDetails.getCode())
                    .eq(HlOtherCommodityDetails::getTeeth, otherCommodityDetails.getTeeth());
            if (ObjectUtils.isNotEmpty(otherCommodityDetails.getBandwidth())) {
                hlOtherCommodityDetailsWrapper.eq(HlOtherCommodityDetails::getBandwidth, otherCommodityDetails.getBandwidth());
            }
            hlOtherCommodityDetailsWrapper.last("limit 1");
            hlOtherCommodityDetails = hlOtherCommodityDetailsMapper.selectOne(hlOtherCommodityDetailsWrapper);

            if (ObjectUtils.isEmpty(hlOtherCommodityDetails) && !"TP".equals(type) && !"IG".equals(type)) {
                hlOtherCommodityDetailsWrapper = new LambdaQueryWrapper<>();
                hlOtherCommodityDetailsWrapper.eq(HlOtherCommodityDetails::getCode, otherCommodityDetails.getCode())
                        .eq(HlOtherCommodityDetails::getTeeth, otherCommodityDetails.getTeeth());

                hlOtherCommodityDetailsWrapper.last("limit 1");
                hlOtherCommodityDetails = hlOtherCommodityDetailsMapper.selectOne(hlOtherCommodityDetailsWrapper);
            }
        }
        return hlOtherCommodityDetails;
    }

    /**
     * 根据轴承布局提取唯一的轴承型号
     * @param chooseTpShape 轴承布局
     * @return 结果
     */
    @Override
    public List<HlOtherCommodityDetails> selectTpAxleHoleTypeList(String chooseTpShape) {
        return hlOtherCommodityDetailsMapper.selectTpAxleHoleTypeList(chooseTpShape);
    }

    /**
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     */


    /**
     * 查询其他型号详情
     * 
     * @param otherId 其他型号详情主键
     * @return 其他型号详情
     */
    @Override
    public HlOtherCommodityDetails selectHlOtherCommodityDetailsByOtherId(Long otherId)
    {
        return hlOtherCommodityDetailsMapper.selectHlOtherCommodityDetailsByOtherId(otherId);
    }

    /**
     * 查询其他型号详情列表
     * 
     * @param hlOtherCommodityDetails 其他型号详情
     * @return 其他型号详情
     */
    @Override
    public List<HlOtherCommodityDetails> selectHlOtherCommodityDetailsList(HlOtherCommodityDetails hlOtherCommodityDetails)
    {
        return hlOtherCommodityDetailsMapper.selectHlOtherCommodityDetailsList(hlOtherCommodityDetails);
    }

    /**
     * 新增其他型号详情
     * 
     * @param hlOtherCommodityDetails 其他型号详情
     * @return 结果
     */
    @Override
    public int insertHlOtherCommodityDetails(HlOtherCommodityDetails hlOtherCommodityDetails)
    {
        return hlOtherCommodityDetailsMapper.insertHlOtherCommodityDetails(hlOtherCommodityDetails);
    }

    /**
     * 修改其他型号详情
     * 
     * @param hlOtherCommodityDetails 其他型号详情
     * @return 结果
     */
    @Override
    public int updateHlOtherCommodityDetails(HlOtherCommodityDetails hlOtherCommodityDetails)
    {
        return hlOtherCommodityDetailsMapper.updateHlOtherCommodityDetails(hlOtherCommodityDetails);
    }

    /**
     * 批量删除其他型号详情
     * 
     * @param otherIds 需要删除的其他型号详情主键
     * @return 结果
     */
    @Override
    public int deleteHlOtherCommodityDetailsByOtherIds(Long[] otherIds)
    {
        return hlOtherCommodityDetailsMapper.deleteHlOtherCommodityDetailsByOtherIds(otherIds);
    }

    /**
     * 删除其他型号详情信息
     * 
     * @param otherId 其他型号详情主键
     * @return 结果
     */
    @Override
    public int deleteHlOtherCommodityDetailsByOtherId(Long otherId)
    {
        return hlOtherCommodityDetailsMapper.deleteHlOtherCommodityDetailsByOtherId(otherId);
    }
}
